#include "BaseApplication.h"
#include <iostream>
#include "Engine.h"
#include "LuaLink.h"


#define WIN32_LEAN_AND_MEAN

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT ) {
	Engine* engine;

    try {
		std::string cmdLine(strCmdLine);

		int pos = cmdLine.find_last_of("/\\");
		if (pos >= 0) {
			cmdLine = cmdLine.substr(pos + 1);
			int pos2 = cmdLine.find_last_of("\"");
			if (pos2 >= 0) {
				cmdLine = cmdLine.substr(0, pos2);
			}
		} else {
			int pos2 = cmdLine.find_last_of("\"");
			if (pos2 >= 0) {
				cmdLine = cmdLine.substr(0, pos2);
			}
		}

		engine = new Engine();

		if (cmdLine.size() > 0) {
			engine->script = cmdLine;
		}

		engine->go();

    } catch( Ogre::Exception& e ) {
		Ogre::LogManager::getSingletonPtr()->logMessage("EXCEPCION EN OGRE:");
		Ogre::LogManager::getSingletonPtr()->logMessage(e.what());
    }
	if (engine != NULL) {
		delete engine;
	}

    return 0;
}
